home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / management / availmem1.02 / availmem.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  14KB  |  485 lines

  1. #include "AvailMem.h"
  2.  
  3.  
  4.  
  5. /***************
  6. *  Prototypes  *
  7. ***************/
  8.  
  9. int  wbmain(struct WBStartup *wbs);
  10. int  main(void);
  11. int  RealMain(void);
  12. int openall(void);
  13. void usage(void);
  14. void UpdateMemBar(void);
  15. Class *InitGaugeMemClass(void);
  16. BOOL FreeGaugeMemClass(void);
  17.  
  18.  
  19. /************
  20. *  Defines  *
  21. ************/
  22.  
  23. #define TEMPLATE  "L=LEFTEDGE/N/K,T=TOPEDGE/N/K,W=WIDTH/N/K,R=REFRESH/N/K,C=COLOR/N/K"
  24. #define MG_Fast   (TAG_USER+0x1100)
  25.  
  26.  
  27. /**************
  28. *  Variables  *
  29. **************/
  30.  
  31. char     Title[80];
  32. APTR     AP_Test;
  33. APTR     WI_Test;
  34. APTR     GA_Chip;
  35. APTR     GA_Fast;
  36.  
  37. Class   *GaugeMemClass = NULL;
  38.  
  39. BYTE                    TimerError     = 0;
  40. struct MsgPort         *TimerMP        = NULL ;
  41. struct timerequest     *TimerIO        = NULL ;
  42. struct Message         *TimerMSG       = NULL;
  43.  
  44. extern struct Library  *UtilityBase;
  45. extern struct ExecBase *SysBase;
  46. struct MemHeader       *memhdr;
  47. APTR                    mem_start;
  48. APTR                    mem_end;
  49. ULONG                   mem_len;
  50.  
  51. struct TextAttr         myTextAttr;
  52. struct RastPort        *rp             = NULL;
  53. struct IntuitionBase   *IntuitionBase  = NULL;
  54. struct Library         *MUIMasterBase  = NULL;
  55. struct Library         *IconBase       = NULL;
  56. struct Window          *window         = NULL;
  57.  
  58. APTR                    VisualInfo     = NULL;
  59. int                     WindowWidth    = 230;
  60. int                     TimeToWait     = 5;
  61. int                     WindowLeftEdge = 0;
  62. int                     WindowTopEdge  = 0;
  63. int                     ColorNumber    = 1;
  64.  
  65. struct IntuiMessage    *imsg           = NULL;
  66. struct I0ExtSer        *reply          = NULL;
  67. struct InputEvent       inputevent     = {0};
  68. BOOL                    Done           = FALSE;
  69. LONG                    windowsignal;
  70. LONG                    timersignal;
  71. long                    mask;
  72. int                     i;
  73.  
  74.  
  75.  
  76.  
  77. /***************
  78. **  wbmain()  **
  79. ***************/
  80.  
  81. int wbmain(struct WBStartup *wbs)
  82. {
  83.    struct DiskObject *dobj = NULL;
  84.    char             **toolsarray;
  85.    char              *s = NULL;
  86.  
  87.  
  88.    if ((IconBase = OpenLibrary("icon.library", 37l)) == NULL)
  89.       return(10);
  90.  
  91.    CurrentDir(wbs->sm_ArgList->wa_Lock);
  92.    if (dobj = (struct DiskObject *) GetDiskObject(wbs->sm_ArgList->wa_Name)) {
  93.       toolsarray = (char **) dobj->do_ToolTypes;
  94.  
  95.       if (s = (char *) FindToolType(toolsarray, "LEFTEDGE"))
  96.          WindowLeftEdge = atoi(s);
  97.       if (s = (char *) FindToolType(toolsarray, "TOPEDGE"))
  98.          WindowTopEdge = atoi(s);
  99.       if (s = (char *) FindToolType(toolsarray, "WIDTH"))
  100.          WindowWidth = atoi(s);
  101.       if (s = (char *) FindToolType(toolsarray, "REFRESH"))
  102.          TimeToWait = atoi(s);
  103.  
  104.       if (s = (char *) FindToolType(toolsarray, "COLOR"))
  105.          ColorNumber = atoi(s);
  106.  
  107.       FreeDiskObject(dobj);
  108.    }
  109.  
  110.    if (IconBase)
  111.       CloseLibrary(IconBase);
  112.  
  113.    return(openall());
  114. }
  115.  
  116.  
  117.  
  118. /*********
  119. *  Main  *
  120. *********/
  121.  
  122. int main(void)
  123. {
  124.    struct RDArgs       *args       = NULL;
  125.    long                 options[5];
  126.  
  127.  
  128.    for (i=0; i<=4; i++)
  129.       options[i] = 0L;
  130.  
  131.    args = ReadArgs(TEMPLATE, options, NULL);
  132.  
  133.    if (args) {
  134.       if (options[0])
  135.          WindowLeftEdge = *(int *) options[0];
  136.       if (options[1])
  137.          WindowTopEdge = *(int *) options[1];
  138.       if (options[2]) {
  139.          WindowWidth = *(int *) options[2];
  140.          if (WindowWidth > 640 || WindowWidth < 100)
  141.             WindowWidth = 200;
  142.       }
  143.       if (options[3])
  144.          TimeToWait = *(int *) options[3];
  145.       if (options[4])
  146.          ColorNumber = *(int *) options[4];
  147.       FreeArgs(args);
  148.    }
  149.    return(openall());
  150. }
  151.  
  152.  
  153.  
  154. /*****************
  155. **  RealMain()  **
  156. *****************/
  157.  
  158. int RealMain(void)
  159. {
  160.    AP_Test = ApplicationObject,
  161.       MUIA_Application_Title, "AvailMem",
  162.       MUIA_Application_Version, "$VER: AvailMem 1.02 (08.12.93)",
  163.       MUIA_Application_Copyright, "Copyright by Dirk Böhmer",
  164.       MUIA_Application_Author, "Dirk Böhmer",
  165.       MUIA_Application_Description, "It shows how much memory you have.",
  166.       MUIA_Application_Base, "AVAILMEM",
  167.       MUIA_Application_SingleTask, FALSE,
  168.       SubWindow, WI_Test = WindowObject,
  169.          MUIA_Window_Title, "AvailMem",
  170.          MUIA_Window_Activate, FALSE,
  171.          WindowContents, VGroup,
  172.             Child, ColGroup(2),
  173.                Child, GA_Fast = BoopsiObject,
  174.                   GaugeFrame,
  175.                   MUIA_Boopsi_Class, GaugeMemClass,
  176.                   MUIA_Boopsi_MinWidth, 100,
  177.                   MUIA_Boopsi_MinHeight, 0,
  178.                   MG_Fast, TRUE,
  179.                   GA_LEFT, 0,
  180.                   GA_TOP, 0,
  181.                   GA_WIDTH, 0,
  182.                   GA_HEIGHT, 0,
  183.                   End,
  184.                Child, Label2("Fast"),
  185.                Child, GA_Chip = BoopsiObject,
  186.                   GaugeFrame,
  187.                   MUIA_Boopsi_Class, GaugeMemClass,
  188.                   MUIA_Boopsi_MinWidth, 50,
  189.                   MUIA_Boopsi_MinHeight, 10,
  190.                   MG_Fast, FALSE,
  191.                   GA_LEFT, 0,
  192.                   GA_TOP, 0,
  193.                   GA_WIDTH, 0,
  194.                   GA_HEIGHT, 0,
  195.                   End,
  196.                Child, Label2("Chip"),
  197.             End,
  198.          End,
  199.       End,
  200.    End;
  201.  
  202.    if (AP_Test) {
  203.       DoMethod(WI_Test, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  204.          AP_Test, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  205.  
  206.       set(WI_Test, MUIA_Window_LeftEdge, WindowLeftEdge);
  207.       set(WI_Test, MUIA_Window_TopEdge, WindowTopEdge);
  208.       set(WI_Test, MUIA_Window_Width, WindowWidth);
  209.       set(WI_Test, MUIA_Window_ScreenTitle, "AvailMem");
  210.       set(WI_Test, MUIA_Window_Open, TRUE);
  211.  
  212.       timersignal  = 1L << TimerMP->mp_SigBit;
  213.  
  214.       TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  215.       TimerIO->tr_time.tv_secs = TimeToWait;
  216.       TimerIO->tr_time.tv_micro = 0;
  217.       SendIO((struct IORequest *) TimerIO);
  218.  
  219.       UpdateMemBar();
  220.  
  221.       while(!Done) {
  222.          ULONG ID, Signal;
  223.          BOOL  Timer;
  224.  
  225.          ID = DoMethod(AP_Test, MUIM_Application_Input, &Signal);
  226.          switch(ID) {
  227.             case MUIV_Application_ReturnID_Quit:
  228.                Done = TRUE;
  229.                break;
  230.             default:
  231.                break;
  232.          }
  233.  
  234.          if (!Done && Signal) Wait(Signal | timersignal);
  235.  
  236.          Timer = FALSE;
  237.          while(reply = (struct I0ExtSer *)GetMsg(TimerMP)) {
  238.             Timer = TRUE;
  239.          }
  240.  
  241.          if (Timer) {
  242.             AbortIO((struct IORequest *) TimerIO);
  243.             WaitIO((struct IORequest *) TimerIO);
  244.             TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  245.             TimerIO->tr_time.tv_secs = TimeToWait;
  246.             TimerIO->tr_time.tv_micro = 0;
  247.             SendIO((struct IORequest *) TimerIO);
  248.  
  249.             UpdateMemBar();
  250.          }
  251.       }
  252.  
  253.       set(WI_Test, MUIA_Window_Open, FALSE);
  254.  
  255.       MUI_DisposeObject(AP_Test);
  256.       return(0);
  257.    } else {
  258.       MUI_Request(0, 0, 0, 0, "Ok", "Couldn't start application");
  259.       return(10);
  260.    }
  261. }
  262.  
  263.  
  264.  
  265. /**************
  266. *  openall()  *
  267. **************/
  268.  
  269. int openall(void)
  270. {
  271.    int return_value = 0;
  272.  
  273.    if ((MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN)) != NULL) {
  274.       if ((TimerMP = CreatePort(NULL, NULL)) != NULL) {
  275.          if ((TimerIO = (struct timerequest *) CreateExtIO(TimerMP, sizeof(struct timerequest))) != NULL) {
  276.             if ((TimerError = OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *) TimerIO, 0L)) == NULL) {
  277.                if ((IntuitionBase = OpenLibrary("intuition.library", 37)) != NULL) {
  278.                   if ((UtilityBase = OpenLibrary("utility.library", 37)) != NULL) {
  279.                      if ((GaugeMemClass = InitGaugeMemClass()) != NULL) {
  280.  
  281.                         return_value = RealMain();
  282.  
  283.                         AbortIO((struct IORequest *) TimerIO);
  284.                         WaitIO((struct IORequest *) TimerIO);
  285.                         FreeGaugeMemClass();
  286.                      } else {
  287.                         MUI_Request(0, 0, 0, 0, "Ok", "Couldn't init GaugeMem");
  288.                         return_value = 5;
  289.                      }
  290.                      CloseLibrary(UtilityBase);
  291.                   } else {
  292.                      MUI_Request(0, 0, 0, 0, "Ok", "Couldn't open u